package com.neusoft.databus.common.connection;

import com.neusoft.bizcore.web.utils.JsonUtils;

import lombok.Getter;
import lombok.Setter;

/**
 * Socket连接配置
 *
 * @author suncf
 */
@Getter
@Setter
public class SocketConnection extends AbstractConnection {

    private static final long serialVersionUID = 1L;

    // IP地址
    private String ipAddress;
    // 端口
    private int port;
    // 读取超时
    private int sotimeout = 3000;
    // 读取超时重试次数
    private int retry = 0;
    // 如果网关配置形同，用来标识连接池的KEY
    private int seq = 0;
    // 验证Socket对象状态时，是否启用"紧急数据包"方法。如果服务器是win7系统，请不要配置改选项。是win7的bug。
    private boolean urgentTest = false;

    @Override
    public boolean equals(final Object o) {
        if (o instanceof SocketConnection) {
            return this.hashCode() == ((SocketConnection) o).hashCode();
        }
        return false;
    }

    @Override
    public int hashCode() {
        return (this.ipAddress + ":" + this.port + ":" + this.seq).hashCode();
    }

    @Override
    public SocketConnection asUsedConnection() {
        return this;
    }

    @Override
    public String toString() {
        return JsonUtils.pojoToJson(this);
    }
}
